#include "databaseplugin.h"
#include "connectionwidget.h"
#include "constants.h"

#include <services/window/windowservice.h>

void DatabasePlugin::initialize()
{
    // 获取窗口服务
    windowService.reset(dpf::ServiceManager::getService<dpf::WindowService>(dpf::WINDOW_SERVICE));
}

bool DatabasePlugin::start()
{
    setupUI();
    initConnection();
    return true;
}

dpf::Plugin::ShutdownFlag DatabasePlugin::stop()
{
    return Sync;
}

void DatabasePlugin::setupUI()
{
    if (!windowService)
        return;

    // 创建数据库连接管理窗口
    auto widget = new ConnectionWidget();
    auto abstractWidget = new dpf::AbstractWidget(widget);
    
    // 注册窗口
    windowService->registerWidget(DATABASE_WINDOW, abstractWidget);
    
    // 在右侧显示窗口
    windowService->showWidgetAtPosition(DATABASE_WINDOW, dpf::WindowService::Position::Right);

    // 添加导航项
    auto action = new dpf::AbstractAction();
    action->setText(tr("Database"));
    action->setIcon(QIcon::fromTheme("database"));
    action->setShortcut(QKeySequence("Ctrl+Alt+D"));
    windowService->addNavigationItem(action, 50);
    
    // 绑定导航项和窗口
    windowService->bindWidgetToNavigation(DATABASE_WINDOW, action);
}

void DatabasePlugin::initConnection()
{
    // 初始化信号槽连接
}